/* 
 * BusinessSupport.java
 * 
 * Data de criação: 12/02/2010
 * 
 * O2SOLUTIONS - SOLUÇÕES EM TECNOLOGIA DA INFORMAÇÃO. 
 *
 */
package br.com.o2solutions.core.business;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import br.com.o2solutions.core.exception.BusinessException;
import br.com.o2solutions.core.integration.repository.DataBaseIntegration;

/**
 * Classe responsável por implementar as funcionalidades basicas negociais das
 * entidades do sistema
 * 
 * @author osvaldeir
 * @since 12/02/2010
 * 
 */
public abstract class BasicBusinessSupport<T> implements BasicBusiness<T> {

	private DataBaseIntegration<T> dataBaseIntegration;

	protected Logger log = LoggerFactory.getLogger(this.getClass());

	/**
	 * {@inheritDoc}
	 * <p>
	 * São aplicadas apenas as regras que implementam a Interface
	 * {@link RemoveRule}.
	 * </p>
	 */

	@Override
	public void remove(T entity) throws BusinessException {
		getDataBaseIntegration().remove(entity);
	}

	/**
	 * {@inheritDoc}
	 * <p>
	 * São aplicadas apenas as regras que implementam a Interface
	 * {@link SaveRule}.
	 * </p>
	 */
	@Override
	public void save(T entity) throws BusinessException {
		getDataBaseIntegration().save(entity);
	}

	/**
	 * {@inheritDoc}
	 * <p>
	 * São aplicadas apenas as regras que implementam as Interfaces
	 * {@link SaveRule} e {@link UpdateRule}.
	 * </p>
	 */
	public void saveOrUpdate(T entity) throws BusinessException {
		getDataBaseIntegration().saveOrUpdate(entity);
	}

	/**
	 * {@inheritDoc}
	 * <p>
	 * São aplicadas apenas as regras que implementam a Interface
	 * {@link UpdateRule}.
	 * </p>
	 */
	@Override
	public void update(T entity) throws BusinessException {
		getDataBaseIntegration().update(entity);
	}

	/**
	 * Retorna o(a) dataBaseIntegration.
	 * 
	 * @return DataBaseIntegration<T>
	 */
	public DataBaseIntegration<T> getDataBaseIntegration() {
		return dataBaseIntegration;
	}

	/**
	 * Atribui o(a) dataBaseIntegration.
	 * 
	 * @param dataBaseIntegration
	 *            DAO
	 */
	@Autowired
	public void setDataBaseIntegration(
			DataBaseIntegration<T> dataBaseIntegration) {
		this.dataBaseIntegration = dataBaseIntegration;
	}

}
